package com.briup.oagg.dataset.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.framework.utils.web.Response;
import com.briup.oagg.dataset.bean.basic.Zone;
import com.briup.oagg.dataset.service.IZoneService;
import com.briup.oagg.dataset.web.vm.ZoneAddVM;
import com.briup.oagg.dataset.web.vm.ZoneUpdateVM;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * 区带信息业务前端控制器
 *
 * @author briup
 */
@Api(tags = "2.区带管理")
@RestController
@RequestMapping("/zone")
@Validated
public class ZoneController {

    @Autowired
    private IZoneService service;

    @ApiOperation(value = "新增区带",notes = "通过输入名称、所属盆地编号和特征描述信息保存信息。输入信息都必填。名称不能重复。")
    @PostMapping
    public Response<String> addZone(@RequestBody @Valid ZoneAddVM zoneAddVM) {
        service.addZone(zoneAddVM);
        return Response.success();
    }

    @ApiOperation(value = "修改区带",notes = "只能修改描述信息")
    @PutMapping
    public Response<String> updateZone(@RequestBody @Valid ZoneUpdateVM zoneUpdateVM) {
        service.updateZone(zoneUpdateVM);
        return Response.success();
    }

    @ApiOperation(value = "删除区带",notes = "根据区带编号删除区带信息及其对应的圈闭和油气藏信息")
    @ApiImplicitParams(
            @ApiImplicitParam(dataType = "string", name = "zoneId", value = "区带id", required = true)
    )
    @DeleteMapping("/{zoneId}")
    public Response<String> deleteById(@PathVariable @NotBlank(message = "区带id不能为空") String zoneId) {
        service.deleteById(zoneId);
        return Response.success();
    }

    @ApiOperation(value = "查询区带总数",notes = "无参")
    @GetMapping("/count")
    public Response<Integer> countNum() {
        int num = service.countNum();
        return Response.success(num);
    }

    @ApiOperation(value = "分页查询区带",notes = "根据盆地编号、每页大小和当前页分页显示信息列表。")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "basinId", value = "盆地id"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码",defaultValue = "1",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "每页大小",defaultValue = "5",required = true,dataTypeClass = Integer.class)
    })
    @GetMapping("/page")
    public Response<Page<Zone>> getZoneByPage(String basinId,@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
        Page<Zone> page = service.findByPage(basinId, pageNum, pageSize);
        return Response.success(page);
    }
}